import {delLocalStorage} from '../../utils/localStorage'
import router from '../../router/index'
const state = {
  drawer: true,
  errorCode: '',
  errorInfo: '',
  isRouterAlive: true,
  night: false,
  customerTheme: false,
  loadMask: false,
  maskTitle: '载入中...',
  items: [
    { icon: 'dashboard', text: 'DashBoard', url: 'dashboard' },
    {
      icon: 'keyboard_arrow_down',
      text: 'Nginx管理',
      'icon-alt': 'devices',
      model: false,
      children: [
        { icon: 'flight_takeoff', text: 'Nginx配置', url: 'nginx' }
      ]
    }
    // { icon: 'keyboard_arrow_down',
    //   text: 'Salt管理',
    //   'icon-alt': 'settings_input_composite',
    //   model: false,
    //   children: [
    //     { icon: 'play_for_work', text: 'SALT控制台', url: 'minions' },
    //     { icon: 'devices_other', text: 'salt临时表', url: 'listsalt' },
    //     { icon: 'network_check', text: 'salt任务表', url: 'listreturns' }
    //   ]
    // },
    // { icon: 'keyboard_arrow_down',
    //   text: '持续集成管理',
    //   'icon-alt': 'cloud_upload',
    //   model: false,
    //   children: [
    //     { icon: 'usb', text: '服务管理', url: 'listservice' },
    //     { icon: 'directions_boat', text: '项目管理', url: 'listproject' },
    //     { icon: 'directions_bike', text: '持续交付', url: 'listPubProject' },
    //     { icon: 'flight_takeoff', text: '今日发布', url: 'todayPublish' }
    //   ]
    // },
    // { icon: 'keyboard_arrow_down',
    //   text: '统计报表',
    //   'icon-alt': 'local_printshop',
    //   model: false,
    //   children: [
    //     { icon: 'developer_board', text: '项目资源报表', url: 'project_report' },
    //     { icon: 'event_note', text: '部门资源报表', url: 'department_report' },
    //     { icon: 'content_paste', text: '项目发布报表', url: 'publish_report' }
    //   ]
    // }
  ]
}

const mutations = {
  moveMenu: (state) => {
    state.drawer = !state.drawer
  },
  logout: (state) => {
    let r = confirm('确认退出？')
    if (r === true) {
      delLocalStorage('admin-token')
      router.push({path: '/login'})
    }
  },
  jump: (state, payload) => {
    router.push({ path: '/' + payload })
  },
  switchMask (state, payload) {
    state.loadMask = payload
  }
}

const actions = {
  moveMenu: ({commit}) => {
    commit('moveMenu')
  },
  logout: ({commit}) => {
    commit('logout')
  },
  jump: ({commit}, payload) => {
    commit('jump', payload)
  },
  switchMask ({commit}, payload) {
    commit('switchMask', payload)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
